﻿using System;
using System.Net;
using System.Threading.Tasks;

namespace MTP
{
    public interface IDispatchServer : IDisposable
    {
        IDispatchServer Run(int port);


        /// <summary>
        /// 启动
        /// </summary>
        /// <returns></returns>
        IDispatchServer Run(int port, IPAddress iPAddress);

        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="port"></param>
        /// <param name="hostname"></param>
        /// <returns></returns>
        IDispatchServer Run(int port, string hostname);

        /// <summary>
        /// 发送单个
        /// </summary>
        /// <param name="package"></param>
        void Send(string clientId, MTPPackage package);

        /// <summary>
        /// 全部发送
        /// </summary>
        /// <param name="package"></param>
        void SendAll(MTPPackage package);
        /// <summary>
        /// 服务器接收消息
        /// </summary>
        /// <param name="serverReceive"></param>
        /// <returns></returns>
        IDispatchServer OnReceive(Func<string, MTPPackage, Task<MTPPackage>> serverReceive);
        /// <summary>
        /// 连接成功
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        IDispatchServer OnConnected(Action<string, IDispatchServer> connected);

        /// <summary>
        /// 连接断开
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        IDispatchServer OnDisconnect(Action<string> disconnect);


        void CloseSync();
    }
}
